package com.shopx.auth.service.impl;


import com.shopx.auth.bean.SysRoleUrl;
import com.shopx.auth.dao.db1.SysRoleUrlDao;
import com.shopx.auth.model.SysRoleUrlModel;
import com.shopx.auth.service.ISysRoleUrlService;
import com.shopx.base.constants.ResultCodeEnum;
import com.shopx.base.exception.ShopxException;
import com.shopx.base.service.base.BaseService;
import com.shopx.cmm.DTO.PageDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @author lituo
 * @className: SysConfigServiceImpl
 * @description: 角色服务
 * @date 2021/12/5 11:24 AM
 */
@Service
@Slf4j
public class SysRoleUrlServiceImpl extends BaseService implements ISysRoleUrlService {

  @Autowired
  private SysRoleUrlDao sysRoleUrlDao;
  @Override
  public SysRoleUrlModel selectByPrimaryKey(SysRoleUrl sysRoleUrl) throws ShopxException {
    if (sysRoleUrl == null) {
      throw new ShopxException(ResultCodeEnum.PAR_NULL);
    }
    sysRoleUrl.setCpId(super.getUserCpId());
    return sysRoleUrlDao.selectByPrimaryKey(sysRoleUrl);
  }

  @Override
  public int insertSelective(SysRoleUrl sysRoleUrl) throws ShopxException {
    if (sysRoleUrl == null) {
      throw new ShopxException(ResultCodeEnum.PAR_NULL);
    }
    sysRoleUrl.setCpId(super.getUserCpId());
    int result = sysRoleUrlDao.insertSelective(sysRoleUrl);
    if (result != 1) {
      throw new ShopxException(ResultCodeEnum.DB_ERROR);
    }
    return result;
  }

  @Override
  public int updateByPrimaryKeySelective(SysRoleUrl sysRoleUrl) throws ShopxException {
    if (sysRoleUrl == null) {
      throw new ShopxException(ResultCodeEnum.PAR_NULL);
    }
    sysRoleUrl.setCpId(super.getUserCpId());
    int result = sysRoleUrlDao.updateByPrimaryKeySelective(sysRoleUrl);
    if (result != 1) {
      throw new ShopxException(ResultCodeEnum.DB_ERROR);
    }
    return result;
  }

  @Override
  public int deleteByPrimaryKey(SysRoleUrl sysRoleUrl) throws ShopxException {
    if (sysRoleUrl == null) {
      throw new ShopxException(ResultCodeEnum.PAR_NULL);
    }
    sysRoleUrl.setCpId(super.getUserCpId());
    int result = sysRoleUrlDao.deleteByPrimaryKey(sysRoleUrl);
    if (result != 1) {
      throw new ShopxException(ResultCodeEnum.DB_ERROR);
    }
    return result;
  }

  private int selectCount(SysRoleUrlModel sysRoleUrl) throws ShopxException {
    return sysRoleUrlDao.selectCount(sysRoleUrl);
  }

  private List<SysRoleUrlModel> selectList(SysRoleUrlModel sysRoleUrl) throws ShopxException {
    List<SysRoleUrlModel> list = sysRoleUrlDao.selectList(sysRoleUrl);
    return list;
  }

  @Override
  public PageDTO<SysRoleUrlModel> getListPage(SysRoleUrlModel sysRoleUrl) throws ShopxException {
    if (sysRoleUrl == null) {
      throw new ShopxException(ResultCodeEnum.PAR_NULL);
    }
    PageDTO<SysRoleUrlModel> pageDTO = new PageDTO<SysRoleUrlModel>();
    sysRoleUrl.setCpId(super.getUserCpId());
    pageDTO.setiTotalDisplayRecords(selectCount(sysRoleUrl));
    pageDTO.setData(selectList(sysRoleUrl));
    return pageDTO;
  }

}

